package com.hee.erp.util;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.base.CaseFormat;
import com.hee.erp.vo.Sorter;
import org.apache.commons.lang3.StringUtils;

public class CommonUtils {

    public static void setQueryOrderCondition(QueryWrapper queryWrapper, Sorter sorter) {
        if (sorter != null) {
            String orderField = sorter.getField();
            String order = sorter.getOrder();
            if(StringUtils.isNotBlank(orderField) && StringUtils.isNotBlank(order)){
                orderField = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, orderField);
                if(order.equals("ascend")){
                    queryWrapper.orderByAsc(orderField);
                }else{
                    queryWrapper.orderByDesc(orderField);
                }
            }
        }
    }
}
